/// <reference path="../../../Resources/js/jquery/jquery.debug.js" />
/// <reference path="../../Additions/Addition.js" />
/// <reference path="../../Items/MItem.js" />
/// <reference name="MicrosoftAjax.debug.js" />

Type.registerNamespace("BM");

// TableDisplayAddition object

BM.TableDisplayAddition = function (item, data) {
    BM.TableDisplayAddition.initializeBase(this, [item, data]);
}

BM.TableDisplayAddition.prototype = {
    load: function () {
        BM.TableDisplayAddition.callBaseMethod(this, 'load');
        var nodeQuery = $(this.item.node);
        if (this.isItemFirst()) {
            this.onFirstSiblingShow(nodeQuery);
        } else {
            nodeQuery.find('.' + LeafItem.Label).hide();
        }
    },

    onFirstSiblingShow: function (nodeQuery) {
        /// <summary>
        /// Turn visibility for labels and add CSS class for title contained in nodeQuery object 
        /// </summary>
        /// <param name="nodeQuery" type="Object" mayBeNull="false">
        /// Object
        /// </param>
        /// <returns />
        nodeQuery.find('.' + LeafItem.Label).show();
        nodeQuery.find('.MForm-Title').addClass("MForm-1stTitle");
    },

    unload: function () {
        BM.TableDisplayAddition.callBaseMethod(this, 'unload');
        var itemIndex = this.item.getIndex();
        var siblings = this.item.getSiblings();
        if (siblings[0] == this.item && siblings.length > 1) {
            this.onFirstSiblingShow($(siblings[1].node));
        }
    },

    isItemFirst: function () {
        var siblings = this.item.getSiblings();
        return siblings[0] == this.item;
    }
}

BM.TableDisplayAddition.registerClass("BM.TableDisplayAddition", BM.Addition);
